package observertest;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
/**
 * these operations are all copy pasted from 
 * http://www.javalobby.org/articles/ultimate-image/
 *
 * @author Jonah
 */
public class ImageOperations {
    
    public ImageOperations() {
        
    }
    
    public static BufferedImage loadImage(String ref) {  
        BufferedImage bimg = null;  
        try {  
  
            bimg = ImageIO.read(new File(ref));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return bimg;  
    } 
    
        public static BufferedImage resize(BufferedImage img, int newW, int newH) {  
            int w = img.getWidth();  
            int h = img.getHeight();  
            BufferedImage dimg = dimg = new BufferedImage(newW, newH, img.getType());  
            Graphics2D g = dimg.createGraphics();  
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
            g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);  
            g.dispose();  
            return dimg;  
        }  
}
